<?php

include_once('Base.php');

class CarverBase extends Base {
    

    private static $instance = null;
 
    // 禁止被实例化
    private function __construct()
    {
        parent::__construct();
    }
 
    // 禁止clone
    private function __clone()
    {
 
    }

    public static function getInstance()
    {
        if (empty(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    /**
     * @desc 初始化Redis连接
     * @params $select_db
     * @auther Carver
     */
    public function initRedis($select_db = 1){
        $redis = new Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->auth('carver');
        $redis->select($select_db);
        return $redis;
    }
    
    /**
     * @desc 初始化Mysql连接
     * @auther Carver
     */
    public function initMysql(){
        $con=new MySQLi("127.0.0.1","carver","carver");
        $con->select_db("carver");
        $sql="select * from test";
        $result = $con->query($sql);
        var_dump($result);die;
        
        
    }
    
    /**
     * @desc 格式化返回的json
     * @params $code
     * @params $msg
     * @params $data
     * @auther Carver
     */
    public function returnJson($code = 0 ,$msg = '',$data=''){
        return parent::returnJson($code,$msg,$data);
    }
}
